home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / turbovis / tvtoyc01.zip / TVVIDEO.CPP < prev    next >
C/C++ Source or Header  |  1994-01-12  |  8KB  |  274 lines

  1. /***************************************************************************
  2.   TVVideo unit
  3.   Turbo Vision extended video modes support routines
  4.   PJB August 30, 1993, Internet mail to d91-pbr@nada.kth.se
  5.   Copyright PJB 1993, All Rights Reserved. Portions Copyright Borland.
  6.   Free source, use at your own risk.
  7.   If modified, please state so if you pass this around.
  8.  
  9.     ■ TVVIDEO NO LONGER SUPPORTS smFont8x8
  10.  
  11.       Use toggleVideoLines instead, or setInternalFont.
  12.  
  13.     ■ PLEASE remember (I didn't) to use
  14.  
  15.       setSpecialVideoMode instead of setVideoMode
  16.  
  17. ***************************************************************************/
  18.  
  19. #define Uses_TApplication
  20. #define Uses_TDeskTop
  21. #define Uses_TMouse
  22. #define Uses_TScreen
  23. #define Uses_TView
  24.  
  25. #include <dos.h>
  26. #include <math.h>
  27. #include <tv.h>
  28. #include "toycfg.h"
  29. #include "tvvideo.h"
  30. #include "video.h"
  31.  
  32.  
  33.  
  34.   int videoScanLines;
  35.   void (*videoModeChanged)() = doNothing;
  36.  
  37.  
  38.   /*******************************************************************
  39.     This is the normal ReloadLastFont void
  40.   *******************************************************************/
  41.   void doNothing()
  42.   {}
  43.  
  44.  
  45.   /*******************************************************************
  46.     From Borlands DRIVERS unit
  47.   *******************************************************************/
  48.   ushort getCrtMode()
  49.   {
  50.     asm {
  51.       PUSH      BP
  52.  
  53.       MOV    AH,0x0F
  54.       INT       0x10
  55.  
  56.       PUSH    AX
  57.       MOV    AX,0x1130
  58.       MOV    BH,0
  59.       MOV    DL,0
  60.       INT       0x10
  61.       POP    AX
  62.  
  63.       MOV    DH,AH
  64.       CMP    DL,25
  65.       SBB    AH,AH
  66.       INC    AH
  67.  
  68.       POP       BP
  69.     }
  70.     return _AL;
  71.   }
  72.  
  73.   /*******************************************************************
  74.     Call this before InitVideo or DoneVideo to stop them from
  75.     changing the video mode. This void *destroys* StartUpMode.
  76.     Save StartUpMode (MyApp.Init; Save=StartUpMode;) if( you want to
  77.     restore the video mode (StartUpMode=Save; MyApp.Done;) on exit.
  78.  
  79.     Try this to keep the startup video mode (132-cols etc) active:
  80.       {
  81.         if( isProbablyTextMode ) preventModeSwitch;
  82.         myApp.init; myApp.run; myApp.done;
  83.       }.
  84.   *******************************************************************/
  85.   void preventModeSwitch()
  86.   {
  87.     TScreen::startupMode=getCrtMode();
  88.     TScreen::screenMode=TScreen::startupMode;
  89.   }
  90.  
  91.  
  92.   /*******************************************************************
  93.     Try to make VideoScanLines reflect maximum number of scan lines
  94.     in this video mode
  95.   *******************************************************************/
  96.   void checkScanLines()
  97.   {
  98.     int scanLines;
  99.  
  100.     scanLines=getCurrentScanLines();
  101.     if ((abs(scanLines-videoScanLines)>16) || (scanLines>videoScanLines))
  102.       videoScanLines=scanLines;       /* Screen size has changed! */
  103.  
  104.  
  105.     #define CHECK(a,b) if (videoScanLines>=a && videoScanLines<=b) videoScanLines=b+1
  106.  
  107.     /* Check if screen could be higher */
  108.     CHECK(340,349);
  109.     CHECK(390,399);
  110.     CHECK(470,479);
  111.     CHECK(590,599);
  112.  
  113.     #undef CHECK
  114.   }
  115.  
  116.  
  117.   /*******************************************************************
  118.     Center all views on the desktop
  119.   *******************************************************************/
  120.   void reCenter(TView *p, void *)
  121.   {
  122.     int x,y;
  123.  
  124.     x=p->origin.x;
  125.     y=p->origin.y;
  126.  
  127.     if (p->options & ofCenterX)
  128.       x=(p->owner->size.x - p->size.x) / 2;
  129.     if (p->options & ofCenterY)
  130.       y=(p->owner->size.y - p->size.y) / 2;
  131.  
  132.     p->moveTo(x, y);
  133.   }
  134.  
  135.   void reCenterDesktop()
  136.   {
  137.     TApplication::deskTop->forEach(reCenter, 0);
  138.     TApplication::application->forEach(reCenter, 0);
  139.   }
  140.  
  141.  
  142.   /*******************************************************************
  143.     Remove all cache buffers
  144.   *******************************************************************/
  145.   void killCache(TView *p, void *)
  146.   {
  147. //    ((TGroup*)p)->freeBuffer();       // And what if it isn't a group?
  148.   }
  149.  
  150.   void killCacheBuffers()
  151.   {
  152.     TApplication::deskTop->forEach(killCache, 0);
  153.     TApplication::application->forEach(killCache, 0);
  154.   }
  155.  
  156.  
  157.   extern TPoint shadowSize;
  158.  
  159.   /*******************************************************************
  160.     Initialize TV video stuff
  161.     This is separate void so we can use it for font changes etc
  162.   *******************************************************************/
  163.   void initTVVideo()
  164.   {
  165.     preventModeSwitch();         /* Disable InitVideo mode switch */
  166.     TScreen::setCrtData();       /* Recalc CRT data */
  167.  
  168.     if (videoType==EGA)          /* This is Borland's idea */
  169.     asm {
  170.       push bp
  171.       mov  es,Seg0040
  172.       or   es:[crtInfo].Byte,1   /* Disable CGA cursor emulation */
  173.  
  174.       mov  ah,1
  175.       mov  cx,0x0600             /* Set cursor size: Start 6, End 0 */
  176.       int  0x10
  177.       pop  bp
  178.     }
  179.  
  180.     killCacheBuffers();          /* Dispose of cache buffers */
  181.  
  182.     TApplication::application->initScreen();   /* Calculate shadow sizes (debatable) */
  183.     TApplication::application->buffer=0;  /* Disable all screen writing */
  184.  
  185.     TRect R(0, 0, TScreen::screenWidth, TScreen::screenHeight);
  186.     TApplication::application->changeBounds(R);    /* Resize application */
  187.     reCenterDesktop();                 /* Center desktop items */
  188.  
  189.     if (isColorMode)         /* Let's hope this works */
  190.       TScreen::screenBuffer=(uchar *)MK_FP(SegB800,0);
  191.     else
  192.     {
  193.       shadowSize.x = 0;
  194.       shadowSize.y = 0;
  195.       TApplication::showMarkers = True;
  196.       TApplication::application->appPalette = apMonochrome;
  197.       TScreen::screenBuffer=(uchar *)MK_FP(SegB000,0);
  198.     }
  199.     TApplication::application->buffer=(ushort *)TScreen::screenBuffer;
  200.  
  201.     TApplication::application->redraw();        /* Draw menubar, desktop and statusline */
  202.     TMouse::show();
  203.  
  204.     checkScanLines();
  205.     TScreen::screenMode=getSpecialVideoMode();
  206.  
  207.     if (Mem(Seg0040,crtRows)!=24)
  208.     asm{                         /* This is Borland's idea */
  209.       mov  ah,0x12               /* Use alternate PrtScr handler */
  210.       mov  bl,0x20
  211.       push bp
  212.       int  0x10
  213.       pop  bp
  214.     }
  215.   }
  216.  
  217.  
  218.   /*******************************************************************
  219.     Use this void to change video mode instead of SetScreenMode
  220.     which will not set modes other than 2,3 and 7.
  221.  
  222.     DON'T use SetScreenMode if( you use SetSpecialVideoMode.
  223.     The display wont be redrawn if( the screen size doesn't change.
  224.     This is a design flaw at the heart of Turbo Vision
  225.   *******************************************************************/
  226.   void setSpecialScreenMode(ushort mode)
  227.   {
  228.     TMouse::hide();
  229.  
  230.     setSpecialVideoMode(mode);
  231.     videoScanLines=getCurrentScanLines();
  232.     videoModeChanged();
  233.  
  234.     initTVVideo();
  235.   }
  236.  
  237.  
  238.   /*******************************************************************
  239.     TV wrapper for Video.UseInternalFont
  240.   *******************************************************************/
  241.   void setInternalFont(uchar font)
  242.   {
  243.     TMouse::hide();
  244.     useInternalFont(font);
  245.     initTVVideo();
  246.   }
  247.  
  248.  
  249.   /*******************************************************************
  250.     Load a character definition table
  251.     Points is the character height
  252.     Font points to an array of character bitmaps for all 256 chars,
  253.     ASCII 0 first, occupying Points bytes per char, top to bottom.
  254.     Character array must contain at least 256*Points bytes.
  255.   *******************************************************************/
  256.   void setUserFont(uchar points, void *font)
  257.   {
  258.     TMouse::hide();
  259.     loadUserFont(points, 0, 256, font);
  260.     initTVVideo();
  261.   }
  262.  
  263.  
  264.   /*******************************************************************
  265.     Replacement code to toggle the number of video lines
  266.   *******************************************************************/
  267.   void toggleVideoLines()
  268.   {
  269.     if (Mem(Seg0040,crtPoints)!=8)
  270.       setInternalFont(internal8x8Font);
  271.     else
  272.       setInternalFont((videoType==EGA) ? internal8x14Font : internal8x16Font);
  273.   }
  274.